

package com.example.administrator.caigou51.recyclerCard.cardView;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.caigou51.R;
import com.example.administrator.caigou51.activity.GoodsDetailsActivity;
import com.example.administrator.caigou51.global.App;
import com.example.administrator.caigou51.recyclerCard.basic.CardItemView;
import com.example.administrator.caigou51.recyclerCard.card.MainPart3Card;
import com.example.administrator.caigou51.util.ImageUtil;


public class MainPart3CardView extends CardItemView<MainPart3Card> {
 	private Context mContext;
    public MainPart3CardView(Context context) {
        super(context);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    public MainPart3CardView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    public MainPart3CardView(Context context,
                                    AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mContext=context;
        // TODO Auto-generated constructor stub
    }
    private LinearLayout linearLayoutRXTJ;
    private TextView textView_icon_rmb;
    private ImageView imageViewLeft;
    private TextView textViewGoodsNameLeft;
    private TextView textViewPriceLSJLeft;
    private TextView textViewRmbLeft;
    private TextView textViewPFJLeft;
    private ImageView imageViewRight,imageViewGoodsTag,imageViewGoodsTag2;
    private TextView textViewGoodsNameRight;
    private TextView textViewPriceLSJRight;
    private TextView textViewRmbRight;
    private TextView textViewPFJRight;
    private TextView textViewPFJ_DESC_RIGHT;
    private TextView textViewPFJ_DESC_LEFT;
    @Override
    public void build(final MainPart3Card card) {
        // TODO Auto-generated method stub
        super.build(card);
        textViewPFJ_DESC_RIGHT = (TextView) findViewById(R.id.textViewPFJ_DESC_RIGHT);
        textViewPFJ_DESC_LEFT = (TextView) findViewById(R.id.textViewPFJ_DESC_LEFT);
        linearLayoutRXTJ = (LinearLayout) findViewById(R.id.linearLayoutRXTJ);
        textView_icon_rmb = (TextView) findViewById(R.id.textView_icon_rmb);
        imageViewLeft = (ImageView) findViewById(R.id.imageViewLeft);
        textViewGoodsNameLeft = (TextView) findViewById(R.id.textViewGoodsNameLeft);
        textViewPriceLSJLeft = (TextView) findViewById(R.id.textViewPriceLSJLeft);
        textViewRmbLeft = (TextView) findViewById(R.id.textViewRmbLeft);
        textViewPFJLeft = (TextView) findViewById(R.id.textViewPFJLeft);
        imageViewRight = (ImageView) findViewById(R.id.imageViewRight);
        textViewGoodsNameRight = (TextView) findViewById(R.id.textViewGoodsNameRight);
        textViewPriceLSJRight = (TextView) findViewById(R.id.textViewPriceLSJRight);
        textViewRmbRight = (TextView) findViewById(R.id.textViewRmbRight);
        textViewPFJRight = (TextView) findViewById(R.id.textViewPFJRight);
        imageViewGoodsTag = (ImageView)findViewById(R.id.imageViewGoodsTag);
        imageViewGoodsTag2 = (ImageView)findViewById(R.id.imageViewGoodsTag2);
        if (card.getIndex()==0)
        {

            linearLayoutRXTJ.setVisibility(View.VISIBLE);
            if (card.isTradeFromSuccess())
            {
                linearLayoutRXTJ.setVisibility(View.GONE);
            }
        }else
        {
            linearLayoutRXTJ.setVisibility(View.GONE);
        }

        if (card.getMainDataBean().getHotsell().get(card.getIndex())!=null)
        {
            String imageUrl=card.getMainDataBean().getHotsell().get(card.getIndex()).getThumb();
            String name=card.getMainDataBean().getHotsell().get(card.getIndex()).getTitle();
            String price=card.getMainDataBean().getHotsell().get(card.getIndex()).getPrice();
            String shipPrice=card.getMainDataBean().getHotsell().get(card.getIndex()).getShip_price();
            String promotionPrice=card.getMainDataBean().getHotsell().get(card.getIndex()).getPromotion_price();
            String getProduct_spec=card.getMainDataBean().getHotsell().get(card.getIndex()).getProduct_spec();
            App.displayImageHttpOrFile(imageUrl,imageViewLeft, ImageUtil.OptionsActivity());
            imageViewLeft.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, GoodsDetailsActivity.class);
                    intent.putExtra(GoodsDetailsActivity.GOODSID,card.getMainDataBean().getHotsell().get(card.getIndex()).getItemid());
                    mContext.startActivity(intent);
                }
            });



            //直降和满减
            //判断促销信息
            if (GoodsDetailCardView.Tag_PuTong.equals(card.getMainDataBean().getHotsell().get(card.getIndex()).getPromotion()))
            {

                imageViewGoodsTag.setVisibility(View.GONE);
                textViewPFJ_DESC_LEFT.setText("批发价：");
                textViewPFJLeft.setText(shipPrice);
            } else if (GoodsDetailCardView.Tag_ZhiJiang.equals(card.getMainDataBean().getHotsell().get(card.getIndex()).getPromotion()))
            {
                imageViewGoodsTag.setVisibility(View.VISIBLE);
                imageViewGoodsTag.setImageResource(R.drawable.icon_zj);
                textViewPFJ_DESC_LEFT.setText("促销价：");
                textViewPFJLeft.setText(promotionPrice);
            }else if (GoodsDetailCardView.Tag_ZheKou.equals(card.getMainDataBean().getHotsell().get(card.getIndex()).getPromotion()))
            {
                imageViewGoodsTag.setVisibility(View.VISIBLE);
                imageViewGoodsTag.setImageResource(R.drawable.icon_zk);
                textViewPFJ_DESC_LEFT.setText("促销价：");
                textViewPFJLeft.setText(promotionPrice);
            }else
            {
                imageViewGoodsTag.setVisibility(View.GONE);
                textViewPFJ_DESC_LEFT.setText("批发价：");
                textViewPFJLeft.setText(shipPrice);
            }
            //判断是否会员
            if (App.getUserBean()!=null && App.getUserBean().getIs_verified()==App.PassValue)
            {
                textViewGoodsNameLeft.setText(name+getProduct_spec);
                textViewPriceLSJLeft.setText(price);
                textViewRmbLeft.setVisibility(View.VISIBLE);
            }
            else
            {
                textViewRmbLeft.setVisibility(View.GONE);
                textViewGoodsNameLeft.setText(name+getProduct_spec);
                textViewPriceLSJLeft.setText(price);
                textViewPFJLeft.setText("会员可见");
            }
        }else
        {
            App.displayImageHttpOrFile("",imageViewLeft, ImageUtil.OptionsActivity());
            textViewGoodsNameLeft.setText("");
            textViewPriceLSJLeft.setText("");
            textViewPFJLeft.setText("");
        }


        if (card.getMainDataBean().getHotsell().get(card.getIndex()+1)!=null)
        {
            String imageUrl=card.getMainDataBean().getHotsell().get(card.getIndex()+1).getThumb();
            String name=card.getMainDataBean().getHotsell().get(card.getIndex()+1).getTitle();
            String price=card.getMainDataBean().getHotsell().get(card.getIndex()+1).getPrice();
            String shipPrice=card.getMainDataBean().getHotsell().get(card.getIndex()+1).getShip_price();
            String promotionPrice=card.getMainDataBean().getHotsell().get(card.getIndex()+1).getPromotion_price();
            String product_spec=card.getMainDataBean().getHotsell().get(card.getIndex()+1).getProduct_spec();
            App.displayImageHttpOrFile(imageUrl,imageViewRight, ImageUtil.OptionsActivity());
            imageViewRight.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, GoodsDetailsActivity.class);
                    intent.putExtra(GoodsDetailsActivity.GOODSID,card.getMainDataBean().getHotsell().get(card.getIndex()+1).getItemid());
                    mContext.startActivity(intent);
                }
            });
            textViewGoodsNameRight.setText(name+product_spec);
            textViewPriceLSJRight.setText(price);
            textViewPFJRight.setText(shipPrice);



            //直降和满减
            //判断促销信息
            if (GoodsDetailCardView.Tag_PuTong.equals(card.getMainDataBean().getHotsell().get(card.getIndex()+1).getPromotion()))
            {

                imageViewGoodsTag2.setVisibility(View.GONE);
                textViewPFJ_DESC_RIGHT.setText("批发价：");
                textViewPFJRight.setText(shipPrice);
            } else if (GoodsDetailCardView.Tag_ZhiJiang.equals(card.getMainDataBean().getHotsell().get(card.getIndex()+1).getPromotion()))
            {
                imageViewGoodsTag2.setVisibility(View.VISIBLE);
                imageViewGoodsTag2.setImageResource(R.drawable.icon_zj);
                textViewPFJ_DESC_RIGHT.setText("促销价：");
                textViewPFJRight.setText(promotionPrice);
            }else if (GoodsDetailCardView.Tag_ZheKou.equals(card.getMainDataBean().getHotsell().get(card.getIndex()+1).getPromotion()))
            {
                imageViewGoodsTag2.setVisibility(View.VISIBLE);
                imageViewGoodsTag2.setImageResource(R.drawable.icon_zk);
                textViewPFJ_DESC_RIGHT.setText("促销价：");
                textViewPFJRight.setText(promotionPrice);
            }else
            {
                imageViewGoodsTag2.setVisibility(View.GONE);
                textViewPFJ_DESC_RIGHT.setText("批发价：");
                textViewPFJRight.setText(shipPrice);
            }
            //判断是否会员
            if (App.getUserBean()!=null && App.getUserBean().getIs_verified()==App.PassValue)
            {
                textViewGoodsNameRight.setText(name+product_spec);
                textViewPriceLSJRight.setText(price);
                textViewRmbRight.setVisibility(View.VISIBLE);
            }else
            {
                textViewRmbRight.setVisibility(View.GONE);
                textViewGoodsNameRight.setText(name+product_spec);
                textViewPriceLSJRight.setText(price);
                textViewPFJRight.setText("会员可见");
            }
        }else
        {
            App.displayImageHttpOrFile("",imageViewRight, ImageUtil.OptionsActivity());
            textViewGoodsNameRight.setText("");
            textViewPriceLSJRight.setText("");
            textViewPFJRight.setText("");
        }



    }
}
